<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Messenger/classes/PhpFox_ComponentSendCrush.class.php, $Author:  $ */



class PhpFox_Mod_Messenger_ComponentSendCrush extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oSrvMessenger = $this->_oModule->getService('Messenger');
        $oSrvAccount = &App::getModuleService('Account', 'Security');
        $oUrl = App::getUrl();
        $oSrvAccount->checkAccess('crush');
        $sBoxName = App::format('Mod_Messenger.send_crush_alert');
		$sTo = $oReq->get('user');
        $aPoems = &App::getTxtFile('poem.txt');
        $bSend = false;
        $sRecipient = $oSrvMessenger->_checkRecipent($oReq->get('user'));
        if($oReq->getInt('send') === 1)
	        $bSend = true;
	    if(!$oReq->get('user') || empty($sRecipient) || strtolower($oReq->get('user')) == strtolower($oSrvAccount->getCurrentUserLogin()))
	    {
	        $bSend = true;
	        $this->addErrors(App::format('Mod_Messenger.member.notexists'));
	    }
        if($oReq->getAction() == 'SendCrush')
        {
            $aPost = $oReq->getAll();

            $aArg = App::getParam('seen');
            $aData['to'] 	= $aPost['user'];
            $aData['title'] = App::getParam('url').$aPost['pics'];
            $aData['text']  = $aPost['text'];
            $aData['seen']  = $aArg['new'];

            $oSrvMessenger->sendMessage($aData, $oSrvAccount->getCurrentUserLogin(), 'crush');
            App::forward($oUrl->getUrl().'send_1', App::format('Mod_Messenger.crush.sent', array($oSrvAccount->getCurrentUserLogin(), $sTo)), 'message', App::getPageName(), 'CrushSent');

        }

		$aTempPoems = array();
		foreach($aPoems as $aPoem)
		{
$aPoem = str_replace("
", ' \n ', $aPoem);
			$aPoem = str_replace("\r", '', $aPoem);
			$aPoem = str_replace("\n", ' \n ', $aPoem);
			$aPoem = str_replace('"', '\"', $aPoem);
			$aTempPoems[] = $aPoem;
		}

        $oTpl = &$this->_oModule->getTemplate();
        $oTpl->assignSrc(array(
        				     'aErrors'		=> $this->getErrors(),
        					 'sPoem'		=> implode('","', $aTempPoems),
        					 'aPoems'		=> $aTempPoems,
        ));
        $oTpl->assign(array(
        				     'sBoxName'		=> $sBoxName,
        					 'sTo'			=> $sTo,
        					 'bSend'		=> $bSend,

        ));

        $sHtml = $oTpl->fetch('SendCrush.html');

        return $sHtml;
    }
}
?>